﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace 第四次作业
{
    public partial class Form1 : Form
    {
        string nowH = DateTime.Now.Hour.ToString();
        string nowM = DateTime.Now.Minute.ToString();
        string nowS = DateTime.Now.Second.ToString();
        string H, M, S;
        bool legal = false;
        public Form1()
        {
            InitializeComponent();
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            nowBox.Text = DateTime.Now.ToString();
            nowH = DateTime.Now.Hour.ToString();
            nowM = DateTime.Now.Minute.ToString();
            nowS = DateTime.Now.Second.ToString();
            int disH = (Convert.ToInt32(H) - Convert.ToInt32(nowH) >= 0) ? Convert.ToInt32(H) - Convert.ToInt32(nowH) : Convert.ToInt32(H) - Convert.ToInt32(nowH) + 24;
            int disM = (Convert.ToInt32(M) - Convert.ToInt32(nowM) >= 0) ? Convert.ToInt32(M) - Convert.ToInt32(nowM) : Convert.ToInt32(M) - Convert.ToInt32(nowM) + 60;
            int disS = (Convert.ToInt32(S) - Convert.ToInt32(nowS) >= 0) ? Convert.ToInt32(S) - Convert.ToInt32(nowS) : Convert.ToInt32(S) - Convert.ToInt32(nowS) + 60;
            if (legal==true)
                distance.Text = disH.ToString() + ":" + disM.ToString() + ":" + disS.ToString();
            if (nowH == H && nowM == M && nowS == S)
            {
                MessageBox.Show("闹钟铃响了！！！！");
            }
        }
        private void Start_Click(object sender, EventArgs e)
        {
            H = textH.Text;
            M = textM.Text;
            S = textS.Text;
            if (Convert.ToInt32(H) > 23 || Convert.ToInt32(M) > 59 || Convert.ToInt32(S) > 59)
            {
                legal = false;
                MessageBox.Show("设定非法！重新输入！");
            }
            else
            {
                MessageBox.Show("设定成功！");
                legal = true;
            }
        }
    }
}